# -- coding: utf-8 --

'''
私有属性不可以在外部直接调用方法，但可以在类的内部增加可调用私有属性的方法

'''
# class Person:
#     def __init__(self, name):
#         self.__name = name
#
#     def get_name(self):
#         return self.__name
#
#     def set_name(self,name):
#         self.__name = name
#
#
# tom = Person('tom')
# #tom.__name = 'jerry'
# print(tom.get_name())
# tom.set_name('boy')
# print(tom.get_name())

'''
私有属性的应用 这样写并不会一改变其中start或end的数据 length不会重新计算长度
'''

# class Segment:
#     def __init__(self,start,end):
#         self.start = start
#         self.end = end
#         self.length = self.end - self.start
#
#     def show(self):
#         print('start = %d,end = %d,length = %d' % (self.start,self.end,self.length))
#
# segment = Segment(20,100)
# segment.show()
# segment.end = 90
# segment.show()

'''
采用下面的方法 把属性都设为私有属性，只能通过特定的方法修改
'''

# class Segment:
#     def __init__(self,start,end):
#         self.__start = start
#         self.__end = end
#         self.__length = self.__end - self.__start
#
#     def get_start(self):
#         return self.__start
#
#     def set_start(self,start):
#         self.__start = start
#         self.__length = self.__end - self.__start
#
#     def get_end(self):
#         return self.__end
#
#     def set_end(self,end):
#         self.__end = end
#         self.__length = self.__end - self.__start
#
#     def get_length(self):
#         return self.__start
#
#     def set_length(self,length):
#         self.__length = length
#
#     def show(self):
#         print('start = %d,end = %d,length = %d' % (self.__start, self.__end, self.__length))
#
# segment = Segment(20,100)
# segment.show()
# segment.set_end(10)
# segment.show()


# 应用

class Private:
    def __parse_word(self,word):
        if word.isdigit():
            print("digit %s" % word)
        elif word.isalpha():
            print("alpha %s" % word)
        elif word == "=" or word == "+" or word == "-":
            print("operator %s" % word)

    def parse_string(self,string):
        words = string.split(' ')
        for word in words:
            self.__parse_word(word)

private = Private()
private.parse_string('sum = sum + 123')

'''
%f 替换浮点数
%d 替换整数
%s 替换字符串
%r 万能替换
'''

